<template>
  <el-table
    ref="multipleTable"
    :data="tableData"
    tooltip-effect="dark"
    style="width: 100%"
    :row-class-name="tableRowClassName"
    @selection-change="handleSelectionChange">
    <el-table-column
      type="selection"
      width="55">
    </el-table-column>
    <el-table-column
      label="日期"
      width="120">
      <template v-slot="scope">{{ scope.row.date }}</template>
    </el-table-column>
    <el-table-column
      prop="name"
      label="姓名"
      width="120">
    </el-table-column>
    <el-table-column
      prop="address"
      label="地址"
      show-overflow-tooltip>
    </el-table-column>
  </el-table>
</template>

<script>
  export default {
    props:{
      tableData:{
        type: Array,
        default: ()=>[]
      }
    },
    data() {
      return {
        selectArr: [],
        multipleSelection: []
      }
    },

    methods: {
      tableRowClassName({row, rowIndex}) {

        if (this.selectArr.includes(rowIndex)) {
          return 'success-row';
        }

        return '';
      },
      toggleSelection(rows) {
        if (rows) {
          rows.forEach(row => {
            this.$refs.multipleTable.toggleRowSelection(row);
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },
      handleSelectionChange(val) {
        let arr = this.tableData;
        this.selectArr = []
        for(let i=0;i<val.length;i++){
          for(let j=0;j<arr.length;j++){
            if(val[i].date == arr[j].date){
              this.selectArr.push(j)
              break;
            }
          }
        }
        
        console.error('选择',val);
        this.multipleSelection = val;
      }
    }
  }
</script>

<style scoped>
  .el-table
  ::v-deep tbody tr:hover > td {
    background: none!important;
  }
 .el-table /deep/ .warning-row {
    background: oldlace;
  }

  .el-table /deep/ .success-row {
    background: #f0f9eb;
  }
</style>